import * as mongoose from 'mongoose';

const CategorySchema = new mongoose.Schema({
  name: String,
  parent: { type: mongoose.SchemaTypes.ObjectId, ref: 'Category' },
});

CategorySchema.virtual('articles', {
  ref: 'Article',
  localField: '_id',
  foreignField: 'category',
  justOne: false,
});

CategorySchema.set('toObject', { getters: true, virtuals: true });
CategorySchema.set('toJSON', { getters: true, virtuals: true });

// module.exports = {CategorySchema}
export { CategorySchema };
